import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'

Vue.use(Router)

let home_routes = [
 
];

let shoppingCart_routes = [

];



let routes = [...home_routes, ...shoppingCart_routes];

routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({
  // mode: 'history',
  routes
});

router.beforeEach((to, from, next) => {
  // const title = to.meta && to.meta.title;
  // if (title) document.title = title;
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (store.state.users.currentUser.UserToken) {
      next();
    }
    else {
      next({
        path: '/login',
        query: { redirect: to.fullPath }
      })
    }
  }
  else {
    next();
  }

})

export default router